home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 14.1 KB | 485 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: MoviePar.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef MOVIEPAR_H
- #include "MoviePar.h"
- #endif
-
- #ifndef MOVIEFRA_H
- #include "MovieFra.h"
- #endif
-
- #ifndef MOVIESEL_H
- #include "MovieSel.h"
- #endif
-
- #ifndef CMOVIE_H
- #include "CMovie.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer Includes -----
-
- #ifndef FWGRAPHX_H
- #include "FWGraphx.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__MOVIES__)
- #include <Movies.h>
- #endif
-
- //========================================================================================
- // Defines
- //========================================================================================
-
- #define kContentAnnotationProp "Apple:ODFMovie:Property:ContentAnnotation"
- #define kContentAnnotationValue "Apple:ODFMovie:Value:ContentAnnotation"
-
- //========================================================================================
- // Runtime informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfmovie
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const short kChooseMovieItemID = 1;
- const short kStartMovieItemID = 3;
- const short kStopMovieItemID = 4;
- const short kSetMovieLoopingItemID = 6;
- const short kShowMovieControllerItemID = 7;
-
- const short kDefaultMoviePicture = 2128;
-
- const short kMovieIdleFreq = 1;
-
- const ODValueType CMoviePart::kPartKind = kODFMovieKind;
- const ODValueType CMoviePart::kPartUserName = kODFMovieEditorUserString;
-
- //========================================================================================
- // CLASS CMoviePart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::CMoviePart
- //----------------------------------------------------------------------------------------
-
- CMoviePart::CMoviePart(ODPart* odPart):
- FW_CPart(odPart, CMoviePart::kPartKind, CMoviePart::kPartUserName, FW_gInstance, kPartIconID),
- fDefaultPicture(),
- fLooping(FALSE),
- fShowController(TRUE),
- fInternalizedMovie(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- CMovie::InitializeQuickTime(); // Throw some error here
-
- fPresentation = RegisterPresentation(ev, "Apple:Presentation:ODFMovie", TRUE, new CMovieSelection(ev, this));
-
- FW_CSharedLibraryResourceFile resFile; // Open the resource file of this shared library
-
- // ----- Arrange Menu -----
- FW_CPullDownMenu* pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kMovieStr);
-
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kChooseMovieStr, cChooseMovie);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kStopMovieStr, kStartMovieStr, cStartStopMovie);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kLoopingStr, cSetMovieLooping);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kHideControllerStr, kShowControllerStr, cShowMovieController);
- this->GetMenuBar(ev)->AdoptMenuLast(ev, pullDownMenu);
-
- RegisterIdle(ev, kMovieIdleFreq);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::~CMoviePart
- //----------------------------------------------------------------------------------------
-
- CMoviePart::~CMoviePart()
- {
- // don't need to delete fDefaultPicture; it will go away automagically
-
- if (fInternalizedMovie)
- delete fInternalizedMovie;
-
- CMovie::TerminateQuickTime();
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::InternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- if (storageUnit->Exists(ev, kODPropContents, this->GetPartKind(ev), 0))
- {
- InternalizeODFMovie(ev, storageUnit);
- }
- #ifdef FW_BUILD_MAC
- else if (storageUnit->Exists(ev, kODPropContents, FW_CPart::gMacMooVFileType, 0))
- {
- InternalizeMovieFile(ev, storageUnit);
- }
- #endif
- else
- FW_DEBUG_MESSAGE("CBitmapPart::InternalizeContent - Unkown type");
- }
-
- //------------------------------------------------------------------------------
- // CMoviePart::InternalizeODFMovie
- //------------------------------------------------------------------------------
-
- void CMoviePart::InternalizeODFMovie(Environment* ev, ODStorageUnit* storageUnit)
- {
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
- FW_CReadableStream archive(&sink);
-
- unsigned long movieSize = sink.GetReadableBytes();
- if (movieSize)
- {
- FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(movieSize); // Throw if null
- FW_ASSERT(movieHandle != NULL);
-
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- archive.Read(*movieHandle, movieSize);
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
-
- if (fInternalizedMovie)
- delete fInternalizedMovie;
-
- fInternalizedMovie = CMovie::CreateNewMovieFromHandle(movieHandle);
- }
-
- if (storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
- {
- FW_CStorageUnitSink sink2(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CReadableStream archive2(&sink2);
- archive2 >> fLooping;
- archive2 >> fShowController;
- }
- }
-
- //------------------------------------------------------------------------------
- // CMoviePart::InternalizeMovieFile
- //------------------------------------------------------------------------------
-
- void CMoviePart::InternalizeMovieFile(Environment* ev, ODStorageUnit* storageUnit)
- {
- if (storageUnit->Exists(ev, kODPropContents, FW_CPart::gMachfsDataType, 0))
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, FW_CPart::gMachfsDataType, 0, kODPosUndefined);
-
- // Get the HFS flavor
- HFSFlavor hfsInfo;
-
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, sizeof(HFSFlavor), byteArray);
- byteArray.CopyBuffer(&hfsInfo, sizeof(HFSFlavor));
-
- if (fInternalizedMovie)
- delete fInternalizedMovie;
-
- // Use the FileSpec in HFS flavor to open the file's data fork
- FW_CFileSpecification fileSpec(hfsInfo.fileSpec);
-
- fInternalizedMovie = CMovie::CreateNewMovieFromFile(fileSpec);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ExternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- FW_PlatformHandle movieHandle = NULL;
-
- CMovieFrame* theMovieFrame;
- if ((theMovieFrame = (CMovieFrame*)this->GetActiveFrame(ev)) != NULL)
- {
- CMovie* theMovie;
- if ((theMovie = theMovieFrame->GetMovie(ev)) != NULL)
- movieHandle = theMovie->GetAsHandle();
- }
-
- ODValueType valueType = this->GetPartKind(ev);
-
- // ----- Clear the value -----
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, valueType, 0, kODPosUndefined);
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, valueType);
-
- if (movieHandle)
- {
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, valueType);
- FW_CWritableStream archive(&sink);
-
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- archive.Write(*movieHandle, FW_CMemoryManager::GetSystemHandleSize(movieHandle));
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
-
- }
-
- {
- // FW_SUAddPropValue correctly test if the property and value exist before
- // trying to create them
- FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
-
- FW_CStorageUnitSink sink2(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CWritableStream archive(&sink2);
- archive << fLooping;
- archive << fShowController;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CMoviePart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
-
- CMovie* theMovie = NULL;
-
- if (this->GetActiveFrame(ev))
- theMovie = ((CMovieFrame*)this->GetActiveFrame(ev))->GetMovie(ev);
-
- return new CMovieFrame(ev, odFrame, presentation, this, theMovie);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::DoIdle
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMoviePart::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
- {
- FW_UNUSED(theNullEvent);
-
- FW_CPresentationFrameIterator iter(fPresentation);
- for (CMovieFrame* movieFrame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); movieFrame = (CMovieFrame*)iter.Next())
- movieFrame->UpdateMovie(ev);
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // CMoviePart::DoMenu
- //------------------------------------------------------------------------------
-
- FW_Boolean CMoviePart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean menuHandled = TRUE;
-
- switch (theMenuEvent.GetCommandID(ev))
- {
- case cChooseMovie:
- this->ChooseMovie(ev);
- break;
-
- case cSetMovieLooping:
- this->ToggleLooping(ev);
- break;
-
- case cShowMovieController:
- this->ToggleController(ev);
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetMovieFromUser
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMoviePart::GetMovieFileFromUser(Environment* ev, FW_CFileSpecification& fileSpec) const
- {
- SFTypeList typeList;
- StandardFileReply reply;
-
- typeList[0] = MovieFileType;
-
- this->GetSession(ev)->GetWindowState(ev)->DeactivateFrontWindows(ev);
- ::StandardGetFilePreview ((FileFilterUPP)NULL, 1, typeList, &reply);
- this->GetSession(ev)->GetWindowState(ev)->ActivateFrontWindows(ev);
-
- if (reply.sfGood == true)
- fileSpec = FW_CFileSpecification(reply.sfFile);
-
- return reply.sfGood;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ChooseMovie
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::ChooseMovie(Environment* ev)
- {
- FW_CFileSpecification fileSpec(FW_CString32("Untitled"));
-
- if (this->GetMovieFileFromUser(ev, fileSpec))
- {
- // ----- I don't need the default picture anymore -----
- if ((const void*)fDefaultPicture != NULL)
- {
- FW_PPicture nullPict;
- fDefaultPicture = nullPict;
- }
-
- FW_CPresentationFrameIterator iter(fPresentation);
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->AdoptNewMovie(ev, CMovie::CreateNewMovieFromFile(fileSpec));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ToggleLooping
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::ToggleLooping(Environment* ev)
- {
- fLooping = !fLooping;
-
- FW_CPresentationFrameIterator iter(fPresentation);
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->ToggleLooping(ev, fLooping);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ToggleController
- //----------------------------------------------------------------------------------------
-
- void CMoviePart::ToggleController(Environment* ev)
- {
- fShowController = !fShowController;
-
- FW_CPresentationFrameIterator iter(fPresentation);
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->ToggleController(ev, fShowController);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetDefaultPicture
- //----------------------------------------------------------------------------------------
-
- FW_PPicture CMoviePart::GetDefaultPicture(Environment *ev) const
- {
- // ----- Load the default picture only if I need it -----
- if ((const void*)fDefaultPicture == NULL)
- {
- FW_CSharedLibraryResourceFile resFile; // Open the resource file of this shared library
- ((CMoviePart*)this)->fDefaultPicture = FW_PPicture(resFile, kDefaultMoviePicture);
- }
-
- return fDefaultPicture;
- }
-
-
-